﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Unity;
using VNext.Finders;

namespace VNext.Core.Packs
{
    public class PackBuilder
    {
        public static void AddServices(IUnityContainer services)
        {
            AppAssemblyFinder assemblyFinder = new AppAssemblyFinder();
            Assembly[] assemblyArray = assemblyFinder.FindAllItems();
            foreach (var assembly in assemblyArray)
            {
                var type = assembly.GetTypes().Where(t => typeof(Pack).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).FirstOrDefault();
                if (type != null)
                {
                    var instance = Activator.CreateInstance(type);
                    (instance as Pack).AddServices(services);
                }
            }
        }
    }
}
